package com.wr.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.wr.model.Comment;
import com.wr.model.RestResponse;
import com.wr.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author weirong
 * @Title:
 * @Description:
 * @date 2018/6/1315:31
 */
@RestController
@RequestMapping("comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @RequestMapping("add")
    public RestResponse<Comment> add(@RequestBody Comment comment) {
        commentService.insertSelective(comment);

        return RestResponse.success();
    }

    @RequestMapping("listByArtId")
    public RestResponse<JSONObject> listByArtId(@RequestParam Integer artid, @RequestParam Integer pageNo) {
        if(pageNo == null || pageNo == 0) {
            pageNo = 1;
        }
        Integer pageSize = 5;

        JSONObject comments = commentService.listByArtId(artid,pageNo,pageSize);

        return RestResponse.success(comments);
    }
}
